import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/home/HomeView.vue'
import LoginView from '../views/login/LoginView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    name: 'login',
    component: LoginView
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/HomeView.vue'),
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  linkActiveClass: "active"
})
router.beforeEach((to, from, next) => {
  if (to.meta.isShow) {
    if (localStorage.getItem('tocken')) {
      next()
    } else {
      next("/home")
    }
  } else {
    next()
  }
})
router.afterEach((to) => {
  document.title = to.meta.title
})
export default router
